package com.sys.utils;

import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 输出json
 */
public class WriteJson {

    public static void write(HttpServletResponse resp,Object obj) throws IOException {
        // 向浏览器返回数据
        PrintWriter writer = resp.getWriter();
        //将java对象，转换成 json 格式的字符串
        ObjectMapper om=new ObjectMapper();
        String json=om.writeValueAsString(obj);
        writer.write(json);
        writer.close();//关闭
    }
}
